<template>
  <el-row :gutter="20">
    <el-form label-width="80px" :model="form" ref="form">
      <el-col :span="6">
        <el-form-item label="标题" prop="name">
          <el-input
            v-model="form.name"
            clearable
            :placeholder="placeholderInput"
          ></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="状态" prop="status">
          <el-select
            v-model="form.status"
            :placeholder="placeholderSelect"
            clearable
            class="full"
          >
            <el-option label="草稿" value="1"></el-option>
            <el-option label="待审核" value="2"></el-option>
            <el-option label="已发布" value="3"></el-option>
            <el-option label="驳回" value="4"></el-option>
            <el-option label="下架" value="5"></el-option>
            <el-option label="回收站" value="6"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="时间" prop="time">
          <el-date-picker
              v-model="form.time"
              type="daterange"
              :picker-options="pickerOptions"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              align="right"
          >
          </el-date-picker>
        </el-form-item>
      </el-col>
      <el-col :span="6" style="text-align: right">
        <el-button type="primary" @click="handleSearch">查询</el-button>
        <el-button @click="handleReset">重置</el-button>
      </el-col>
    </el-form>
  </el-row>
</template>

<script>
import { PLEASE_INPUT, PLEASE_SELECT } from "@/util/constant";
import dayjs from "dayjs";
export default {
  props: ["moduleList"],
  data() {
    return {
      form: {
        name: "",
        menuId: "",
        status: "",
        time: "",
        keyword: "",
        moduleIdList: [],
      },
      optionProps: {
        value: "moduleId",
        label: "moduleName",
        children: "childList",
      },
      placeholderInput: PLEASE_INPUT,
      placeholderSelect: PLEASE_SELECT,
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  methods: {
    handleSearch() {
      if (this.form.time) {
        this.form.startDate = dayjs(this.form.time[0]).format("YYYY-MM-DD");
        this.form.endDate = dayjs(this.form.time[1]).format("YYYY-MM-DD");
        // delete this.form.time;
      }
      this.$emit("getTableData", { ...this.form });
    },
    handleReset() {
      this.$refs.form.resetFields();
      this.form = {}
      this.$emit("getTableData", { ...this.form });
    },
  },
};
</script>
